﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FDStudio.Core.Entities
{
    /*
     CreatedOn: 2018-02-25
     CreatedBy: Jackie Lee(天宇遊龍)
     */
    /// <summary>
    /// service请求结果
    /// </summary>
    public class ServiceResult : IServiceResult
    {
        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; private set; }

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ServiceResult OK(string message)
        {
            return new ServiceResult
            {
                Success = true,
                Message = message
            };
        }

        /// <summary>
        /// 不确定
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ServiceResult Result(bool bSuccess, string message)
        {
            return new ServiceResult
            {
                Success = bSuccess,
                Message = message
            };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ServiceResult Failure(string message)
        {
            return new ServiceResult
            {
                Success = false,
                Message = message
            };
        }
    }

    /// <summary>
    /// 含有结果的api请求结果
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ServiceResult<T> : IServiceResult<T>
    {
        public string Message { get; set; }

        public bool Success { get; private set; }

        /// <summary>
        /// 结果
        /// </summary>
        public T Result { get; private set; }

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ServiceResult<T> OK(T result, string message)
        {
            return new ServiceResult<T>
            {
                Success = true,
                Message = message,
                Result = result
            };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ServiceResult<T> Failure(string message)
        {
            return new ServiceResult<T>
            {
                Success = false,
                Message = message,
                Result = default(T)
            };
        }
    }
}
